package com.example.mylibrary;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class LayoutManagerFactory {
    public enum Orientation {
        VERTICAL(1), HORIZENAL(2);
        private int value;

        Orientation(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    public interface RecyclerViewImpl {
        int colume();

        RecyclerView.LayoutManager createLinearRv(RecyclerView recyclerView, Orientation orientation);

        RecyclerView.LayoutManager createGridRv(RecyclerView recyclerView, int cloumecount);
    }

    public abstract static class abGridRv implements RecyclerViewImpl {
        @Override
        public RecyclerView.LayoutManager createLinearRv(RecyclerView recyclerView, Orientation orientation) {
            return null;
        }

        @Override
        public int colume() {
            return 0;
        }
    }

    public abstract static class abLineaRv implements RecyclerViewImpl {
        @Override
        public RecyclerView.LayoutManager createGridRv(RecyclerView recyclerView, int colume) {
            return null;
        }

        @Override
        public int colume() {
            return 0;
        }

    }

    public static RecyclerViewImpl linear() {
        return new abLineaRv() {
            @Override
            public RecyclerView.LayoutManager createLinearRv(RecyclerView recyclerView, Orientation orientation) {
                return new LinearLayoutManager(recyclerView.getContext(), orientation.value, false);
            }
        };
    }

    public static RecyclerViewImpl grid() {
        return new abGridRv() {
            @Override
            public RecyclerView.LayoutManager createGridRv(RecyclerView recyclerView, int cloumecount) {
                return new GridLayoutManager(recyclerView.getContext(), cloumecount);
            }
        };
    }

}
